// global是nodejs中类似于window的对象
function fun1(stuNo){
    if(stuNo==='s1001')
        return 1
    else 
        return 0
}
function fun2(id){
    if(id===1){
        return 2
    }else{
        return 0
    }
}
function fun3(id){
    if(id===2){
        return 'ok'
    }else{
        return 'no'
    }
}

function start(stuNo){
    let id1 = fun1(stuNo)
    if(id1===1){
        let id2 = fun2(id1)
        if(id2 === 2){
            let res = fun3(id2)
            if(res === 'ok'){
                console.log('欢迎光临~~');
            }
        }
    }
}
start('s1001')


function one(stuNo){
    return new Promise((resolve,reject)=>{
        if(stuNo==='s1001')
            resolve(1)
        else 
            reject(0)
    })
}

function two(id){
    return new Promise((resolve,reject)=>{
        if(id===1){
            resolve(2)
        }else{
            reject(0)
        }
    })
}
function three(id){
    return new Promise((resolve,reject)=>{
        if(id===2){
            resolve('ok')
        }else{
            reject('no')
        }
    })
}

function go(stuNo){
    one(stuNo)
    .then(id1=>{return two(id1)})
    .then(id2=>{return three(id2)})
    .then(res=>{
        if(res==='ok'){
            console.log('欢迎光临~~');
        }
    })
}
go('s1001')

async function go2(stuNo){
    let id1 = await one(stuNo)
    let id2 = await two(id1)
    let res = await three(id2)
    if(res){
        console.log('欢迎光临~~');
    }
}

go2('s1001')



